* This script contains the code to replicate TableH of the online appendix in Ductor, L., Fafchamps, M., Goyal S. and M. van der Leij. Social Networks and Research Output. The Review of Economics and Statistics. 

log using TableH.log, replace
use prodndnp_qnt.dta, clear
order auth year t tsq lcprod5 lcprodl5 lprodf3 lprodf3l-lprodf3l13 prod prodf5 mt qnt cprod cprod5 cprodl5 mnauthors ystart yend nopapers group prodf3 degree1y degree2y degree3y degree4y degree5y degree6y degree7y degree8y degree9y degree10y degree11y degree12y degree13y degree14y degree15y degree21y degree22y degree23y degree24y degree25y degree26y degree27y degree28y degree29y degree210y degree211y degree212y degree213y degree214y degree215y gc1y gc2y gc3y gc4y gc5y gc6y gc7y gc8y gc9y gc10y gc11y gc12y gc13y gc14y gc15y lnetprod1y lnetprod2y lnetprod3y lnetprod4y lnetprod5y lnetprod6y lnetprod7y lnetprod8y lnetprod9y lnetprod10y lnetprod11y lnetprod12y lnetprod13y lnetprod14y lnetprod15y lnetprod21y lnetprod22y lnetprod23y lnetprod24y lnetprod25y lnetprod26y lnetprod27y lnetprod28y lnetprod29y lnetprod210y lnetprod211y lnetprod212y lnetprod213y lnetprod214y lnetprod215y lbet1y lbet2y lbet3y lbet4y lbet5y lbet6y lbet7y lbet8y lbet9y lbet10y lbet11y lbet12y lbet13y lbet14y lbet15y
set more off
set matsize 800

/*******OLS REGRESIONS**************/

/*OLS out-of-sample program*/
cap pro drop ols_os
program define ols_os
syntax varlist(numeric min=1) [if]
marksample touse
reg `varlist' if `touse', vce(cluster auth)
qui scalar n1=e(N)
estat ic
scalar rmseols=e(rmse)
predict ybols if group==2 & lprodf3<., xb 
scalar r2i1ols= e(r2)   /*computing the R2 of the baseline model*/
qui gen sqerrols= (lprodf3-ybols)^2 if ybols<.
quietly egen peols=sum(sqerrols)if ybols<.  /*RSEE of the predicted model*/
quietly sum peols    /*summarizing the RSEE*/
quietly scalar rssols=r(max)  /*obtaining the total RSEE*/
quietly scalar nols=r(N)    /*number of observations in group 2*/
scalar rmseo2ols=(rssols/nols)^0.5   /*RMSE out of sample*/
di rmseols   "  Pooled OLS in-sample RMSE"
di n1 " Number of observations in the in-sample group"
di rmseo2ols "  Pooled OLS out-of-sample RMSE"
di nols " Number of observations in the out-of-sample group"
drop peols ybols
end


reg lprodf3 y2-y27 nopapers t2-t27 if group==1
gen e=1 if e(sample) 
qui scalar n1=e(N)
estat ic
scalar rmseols=e(rmse)
predict ybols if group==2 & lprodf3<., xb 
scalar r2i1ols= e(r2)   /*computing the R2 of the baseline model*/
qui gen sqerrolsM0= (lprodf3-ybols)^2 if ybols<.
quietly egen peols=sum(sqerrolsM0)if ybols<.  /*RSEE of the predicted model*/
quietly sum peols    /*summarizing the RSEE*/
quietly scalar rssols=r(max)  /*obtaining the total RSEE*/
quietly scalar nols=r(N)    /*number of observations in group 2*/
scalar rmseo2ols=(rssols/nols)^0.5   /*RMSE out of sample*/
di rmseols   "  Pooled OLS in-sample RMSE"
di n1 " Number of observations in the in-sample group"
di rmseo2ols "  Pooled OLS out-of-sample RMSE"
di nols " Number of observations in the out-of-sample group"
drop peols ybols


/*MODEL 1*/

reg lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 if e==1
qui scalar n1=e(N)
estat ic
scalar rmseols=e(rmse)
predict ybols if group==2 & lprodf3<., xb 
scalar r2i1ols= e(r2)   /*computing the R2 of the baseline model*/
qui gen sqerrolsM1= (lprodf3-ybols)^2 if ybols<.
quietly egen peols=sum(sqerrolsM1)if ybols<.  /*RSEE of the predicted model*/
quietly sum peols    /*summarizing the RSEE*/
quietly scalar rssols=r(max)  /*obtaining the total RSEE*/
quietly scalar nols=r(N)    /*number of observations in group 2*/
scalar rmseo2ols=(rssols/nols)^0.5   /*RMSE out of sample*/
di rmseols   "  Pooled OLS in-sample RMSE"
di n1 " Number of observations in the in-sample group"
di rmseo2ols "  Pooled OLS out-of-sample RMSE"
di nols " Number of observations in the out-of-sample group"
drop peols ybols

/*****MOdel 2*****/

/*Coauthors productivity*/
ols_os lprodf3 y2-y27 nopapers t2-t27  lnetprod1y lnetprod2y lnetprod3y lnetprod4y lnetprod5y lnetprod6y lnetprod7y lnetprod8y lnetprod9y lnetprod10y lnetprod11y lnetprod12y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(12) force
drop sqerrols diffsqerrlM2


/*Coauthors' coauthors productivity*/
ols_os lprodf3 y2-y27 nopapers t2-t27  lnetprod21y lnetprod22y lnetprod23y lnetprod24y lnetprod25y lnetprod26y lnetprod27y lnetprod28y lnetprod29y lnetprod210y lnetprod211y lnetprod212y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(12) force
drop sqerrols diffsqerrlM2
/*Degree*/
ols_os lprodf3 y2-y27 nopapers t2-t27  degree1y degree2y degree3y degree4y degree5y degree6y degree7y degree8y degree9y degree10y degree11y degree12y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(12) force
drop sqerrols diffsqerrlM2
/*Degree 2*/
ols_os lprodf3 y2-y27 nopapers t2-t27  degree21y degree22y degree23y degree24y degree25y degree26y degree27y degree28y degree29y degree210y degree211y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(11) force
drop sqerrols diffsqerrlM2
/* Giant component*/
ols_os lprodf3 y2-y27 nopapers t2-t27  gc1y gc2y-gc15y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(15) force
drop sqerrols diffsqerrlM2
/* Betweenness*/
ols_os lprodf3 y2-y27 nopapers t2-t27  gc1y gc2y-gc15y lbet1y-lbet15y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(15) force
drop sqerrols diffsqerrlM2
/*Closeness*/
ols_os lprodf3 y2-y27 nopapers t2-t27  gc1y gc2y-gc15y lclos1y-lclos15y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(15) force
drop sqerrols diffsqerrlM2
/*Coauthors top 1 dummy variable*/
ols_os lprodf3 y2-y27 nopapers t2-t27  neiq11y neiq12y neiq13y neiq14y neiq15y neiq16y neiq17y neiq18y neiq19y neiq110y neiq111y neiq112y neiq113y neiq114y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(14) force
drop sqerrols diffsqerrlM2

/*****MV Model 2*****/

ols_os lprodf3 y2-y27 nopapers t2-t27 lnetprod1y-lnetprod12y lnetprod21y-lnetprod212y degree1y-degree12y degree21y-degree212y gc1y-gc12y lbet1y-lbet12y lclos1y-lclos12y neiq11y-neiq112y if e==1
gen diffsqerrlM2= sqerrols-sqerrolsM1
newey2 diffsqerrlM2 if group==2 & lprodf3<., lag(12) force
drop sqerrols diffsqerrlM2

/* Model 3*/

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 lnetprod1y-lnetprod6y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 lnetprod21y-lnetprod210y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 degree1y-degree5y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 degree21y-degree25y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 gc1y-gc8y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 gc1y-gc9y lbet1y-lbet9y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3
ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 gc1y-gc7y lclos1y-lclos7y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3
ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 neiq11y-neiq16y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3
/*****MV Model 3*****/

ols_os lprodf3 y2-y27 nopapers t2-t27 lprodf3l-lprodf3l13 lnetprod1y-lnetprod6y lnetprod21y-lnetprod26y degree1y-degree6y degree21y-degree26y gc1y-gc6y lbet1y-lbet6y lclos1y-lclos6y neiq11y-neiq16y if e==1
gen diffsqerrlM3= sqerrols-sqerrolsM1
newey2 diffsqerrlM3 if group==2 & lprodf3<., lag(13) force
drop sqerrols diffsqerrlM3

log close

